﻿@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutDialog.cshtml";
   ViewBag.Title = "百度地图";
}

@section HeaderContent{
   <script src="http://api.map.baidu.com/api?v=2.0&ak=826e806b86676d155282de3d37188137"></script>
   <script src="http://api.map.baidu.com/library/MarkerTool/1.2/src/MarkerTool_min.js"></script>
   <script src="http://api.map.baidu.com/library/CityList/1.4/src/CityList_min.js"></script>
   <style>
	.content{position:relative;width:550px;height:350px;}
	#f_container{border:1px solid #999999;position:absolute;top:10px;left:10px;z-index:1000;font-size:14px;}
	#container{width:290px;overflow:hidden;height:20px;background:#F2F3F5;border:5px solid #F2F3F5;}
	#container select{border:1px solid #ccc;font-size:14px;}
   </style>
   <script>
      var api = top.dialog.get(window); //获取父窗体对象
      //页面加载完成执行
      $(function () {
         //设置按钮及事件
         api.button([{
            value: '确定',
            callback: function () {
               $(api.data).parents("body").find("#txtXPoint").val($("#lat").val());
               $(api.data).parents("body").find("#txtYPoint").val($("#lng").val());
            },
            autofocus: true
         }, {
            value: '取消',
            callback: function () { return true; }
         }
         ]);
      });
   </script>
}

<div class="content">
  <div id="f_container">
    <div id="container"></div>
  </div>
  <div id="allmap" style="width:550px;height:350px;"></div>
  <input type="hidden" id="lat" />
  <input type="hidden" id="lng" />
</div>

<script>
   // 百度地图API功能
   var map = new BMap.Map("allmap");            // 创建Map实例
   map.enableScrollWheelZoom(true);
   map.addControl(new BMap.ScaleControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));    // 右下比例尺
   map.setDefaultCursor("Crosshair"); //鼠标样式
   map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT }));  //右上角，仅包含平移和缩放按钮
   var cityList = new BMapLib.CityList({
      container: 'container',
      map: map
   });
   map.addEventListener("click", showInfo);
   function showInfo(e) {
      map.clearOverlays();
      marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat));  // 创建标注
      map.addOverlay(marker);
      //获取经纬度
      document.getElementById("lng").value = e.point.lng;
      document.getElementById("lat").value = e.point.lat;
   }
</script>